package com.doudoukeji.service.Activity.mypatient;

import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.doudoukeji.service.Dialog.CallPhoneDialog;
import com.doudoukeji.service.R;
import com.sanhai.android.util.TimeUitl;

import java.util.List;

/**
 * @version 2.0
 * @类描述： 我的患者界面
 * @项目名称：ddgh
 * @类名称： MyPatientListActivity
 * @包名称： com.doudoukeji.service.Activity.myatient
 * @创建人：张强 boy
 * @创建时间：2016/3/9 14:06
 * @修改人：
 * @修改时间：2016/3/9 14:06
 * @修改备注： new parent class(用一句话描述修改了什么)
 */
public class MyPatientListAdapter extends BaseAdapter {
    private Context context;
    private List<MyPatientListBean> infos;

    public MyPatientListAdapter(Context context, List<MyPatientListBean> infos) {
        this.context = context;
        this.infos = infos;
    }

    @Override
    public int getCount() {
        return infos.size();
    }

    @Override
    public Object getItem(int position) {
        return infos.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public class ViewHolder {
        TextView mTvName;
        TextView mTvPhone;
        TextView mTvCreateDate;
        ImageView mImgCall;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        View view;
        final ViewHolder holder;
        if (convertView != null) {
            view = convertView;
            holder = (ViewHolder) view.getTag();
        } else {
            view = View.inflate(context, R.layout.item_mypatient, null);
            holder = new ViewHolder();
            holder.mTvName = (TextView) view.findViewById(R.id.tv_user_name);
            holder.mTvPhone = (TextView) view.findViewById(R.id.tv_phone);
            holder.mTvCreateDate = (TextView) view.findViewById(R.id.tv_data);
            holder.mImgCall = (ImageView) view.findViewById(R.id.img_call);
            view.setTag(holder);
        }

        MyPatientListBean textbean = null;
        if (infos != null) {
            textbean = infos.get(position);
            holder.mTvName.setText(textbean.getClientName());
            holder.mTvPhone.setText(textbean.getPhone());
            holder.mTvCreateDate.setText(TimeUitl.getDayStr(textbean.getCreateDate()));
        }

        final MyPatientListBean finalTextbean = textbean;
        holder.mImgCall.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                CallPhoneDialog dialog = new CallPhoneDialog(
                        context, finalTextbean.getPhone());
                dialog.show();
            }
        });

        return view;
    }

}
